Skip to main content

Full text of "The Home Computer Advanced Course 66"

See other formats
















RESIDENT EXPERT Our series on 
artificial intelligence considers the 1307 
development of expert systems — programs 
that incorporate highly specialised areas of 

knowledge 


COMEBACK BID Weighing in with a 
stylish design, large memory and seductive 1309 
price, the Atari 130XE looks like it could 
have the makings of a champ 





EXTENDED VIEW We take a look at how 
CP/M labels and manipulates its files _ 1304 


ICON TACT Beyond Software’s 
Shadowfire uses Mac-like icons as part of a 1370 


poems fast-action game : 1) The Atari 130XE possesses one more chip than its 
= _____ predecessors. What is its name and function? 

2) What is the general effect of a CALL command in 

780 Assembly language? 

3) Whatis a ‘wildcard’? 


COMPUTER SCIENCE 


SEARCHING LOOKS A sisctanins ne 
PROLOG’S unique tree-like search procedure 









~ FROM PET TO PLOTTER A weekly 
glossary of computing terms 1308 


THE NEW WORLD I The first in a three- 
part complete listing of our New World 137 4 | 
simulation game. This week we provide 
flavours for the Spectrum 





BM PC COURTESY OF CUP ERE 114 CHARING CROSS ROAD, LONDON WC2 









CHANNELS OF THOUGHT We 
investigate how the Spectrum sends data to 137 A 
the screen and ZX printer via channels 


DIGITAL DOODLES Our digital tracer 
project concludes by adding some 1306 
refinements to the control program we gave 

last week 





REFERENCE CARD Another section of - INSIDE 


the Commodore 64’s memory map | us 








COVER PHOTOGRAPHY BY MARCUS WILSON SMITH 








RESIDENT EXPERT 





This instalment of our series on artificial 
intelligence focuses on expert systems — 
highly structured programs capable of 
fulfillimg much of the diagnostic and 


advisory role of professional human 
practitioners in specialised areas of 
knowledge. We _ isolate the _ essential 
ingredients of the true expert system. 





A human expert — a hospital consultant, a 
geologist, or a chemical analyst, for example — is 
usually someone we respect. Experts spend a long 
time studying and practising their skills to enable 
them to do their jobs well. The trouble with human 
experts, however, is that they are scarce, they are 
not always reliable, they want payment, and in the, 
long run they die, taking much of their expertise 
with them. Many people are therefore keen on the 
idea of encoding expertise in computer programs, 
to get the benefits of being able to draw on a large 
body of knowledge without the drawbacks 
associated with the human experts. 

The concept of the ‘expert system’ arose in the 
1970s, when artificial intelligence (AI) researchers 
abandoned, or postponed, the quest for generally 
intelligent machines and turned instead to the 
solution of narrowly focused real-world problems. 
Thus the expert system is one of the first examples 
of applied AI, and expert systems techniques have 
spread out far beyond the confines of the research 
laboratories in which they were devised. Indeed, 
expert systems have to an extent brought AI into 
practical everyday use. Systems already exist that 
out-perform skilled humans at medical diagnosis, 
mass-spectrogram interpretation, classifying crop 
disease and much else besides. It is worth asking, 
therefore, how they work. 


WHAT IS AN EXPERT SYSTEM? 


Typically an expert system is based on an extensive 
body of knowledge about a specific problem area. 
In general, this knowledge will be organised as a 
collection of rules that allow the system to draw 
conclusions from given data or premises, thereby 
enabling it to offer intelligent advice or take 
intelligent decisions. This knowledge-based 
approach to systems design represents an 
evolutionary change within computer science, 
with revolutionary consequences. It replaces the 
traditional formula of ‘Data + Algorithm = 
Program’ with a new architecture centred around a 
‘knowledge base’ and an ‘inference engine’, so that 
‘Knowledge + Inference = Expert System’. This 
formula is obviously similar, but different enough 
in approach to have profound implications. 


MARCUS WILSON-SMITH 


What is an expert system? The following 
checklist of typical features should prove helpful. 


@An expert system is limited to a relatively narrow 
domain of expertise. 
@It should be able to reason with uncertain data 
and unreliable rules. 


et must be able to explain its train of reasoning in © 


a comprehensive way. 
@F acts and inference mechanism are ‘detachable’: 


knowledge is not ‘hard-coded’ into the deductive 


procedures. 

elt is designed to grow incrementally. 

@It is typically rule-based. 

@It delivers advice as its output — not tables of 
figures or graphs. 


The key word is knowledge. Clearly the objective 
of an intelligent problem-solving system is to cut 
out blind or random search. To do so a computer 
system has to exploit the same advantage that the 
human expert has over the novice — that is, 
expertise, or organised knowledge: knowledge 
about facts, about rules of inference and about 
solution strategies. There are four essential 
components of a fully fledged expert system: 


1. The knowledge base 

2. The inference engine 

3. The knowledge-acquisition module 
4. The explanatory interface 



















Seeking Professional Advice 
Systems that can acquire 
knowledge from experts and use 
that knowledge to proffer advice 
or diagnoses are becoming 
increasingly popular in many 
disciplines —.from medicine to 
farming and architecture. Expert 
systems, designed to operate 
within a narrow subject area, 
provide professionals with an 
on-line consultancy service to 
assist them in their work 


THE HOME COMPUTER ADVANCED COURSE 1301 


HSOLNIOVW JHL NO TIANNINSW NVI 





System Synopsis 


_ Anexpert system comprises 


several modules that allow 
knowledge to pass from the 
expert to the end user. 
Knowledge must first be 
acquired from the expert(s) and 
incorporated into a knowledge - 
base. In order to make 
predictions, give advice or 
provide a diagnosis, the system 
must then be able to draw 
inferences from the knowledge 
base. Finally, the explanatory 


_ interface allows the user to 


communicate with the system in 
order to consult it 





All four modules are critical. A knowledge-based 
system may lack one or other of them, but a truly 
expert system should not. We will consider each of 
these four modules in turn and explain how they 
work together. 


THE KNOWLEDGE BASE 


The two fundamental components of an expert 
system are the knowledge base and the inference 
engine. The knowledge base stores information 
about the subject domain; however, information 
in a knowledge base is not the passive set of 
records and items that you would find in a 
conventional database. Instead it contains 
symbolic representations of experts’ rules of 
judgment and experience in a form that enables 
the inference engine to perform logical deductions 
from it. 

Most of the items in a knowledge base are non- 
mathematical. The two chief difficulties in 
developing a knowledge base are knowledge 
representation and knowledge acquisition. ‘The 
former problem concerns the decision on how to 
encode knowledge so that the computer can use it. 
In general the following elements must be 
represented: domain terms (the jargon used by 
experts in the field); structural relationships (the 
interconnections of component entities); and 


1302 THE HOME COMPUTER ADVANCED COURSE 





causal relationships (the cause-effect relations 
between components). 

The task of the knowledge engineer is to select 
appropriate means of storing such information 
symbolically. Four main methods have evolved: 


@®Rules in IF...THEN format. The condition 
specifies some pattern and the conclusion may be 
an action or assertion. | 

@ Semantic nets. These represent relations among 
objects in the domain (e.g. the whale is amammal) 
by links between nodes. 

®Frames. These are generalised record structures 
which may have default values and may have 
actions coded as the values of certain fields or 
slots. 

® Horn clauses. This is a form of predicate logic on 
which PROLOG is based and with which the PROLOG 
system can perform inferences (see page 1272). 


Early expert systems used the rule-based 
formalism almost exclusively. A sample rule from 
the Mycin system for diagnosing blood infections 
is typical of the IF. . .THEN structure: 
IF: 
1. The infection requiring therapy is meningitis, and 
2. The type of infection is fungal, and 
3. Organisms were not seen on the stain of the 
culture, and 
4. The patient is not a compromised host, and 
5. The patient has been in a region where 
coccidiomycoses are endemic, and 
6. The race of the patient is black or Asian or Indian, 
and 
7. The cryptococcal antigen in the csf was not positive 
THEN 
There is suggestive evidence that cryptococcus is not 
one of the organisms which might be causing the 
infection. 


From this example we can see that an expert 
system uses the technical jargon of the area in 
which it is designed to operate — in this case 
medicine. The IF. . .THEN construct used by Mycin 
is essentially a series of statements that can be 
determined as true or false. Thus, the statements 
can be linked by Boolean operators, such as AND, 
to assist computer manipulation. In order to elicit 
the information required to make a diagnosis, 
Mycin must enter into a dialogue with the system 
user. Obviously, in this system at least, the user 
must have a certain level of knowledge in the 
subject area, so that the expert system’s queries 
can be understood and answered. 


THE INFERENCE ENGINE 


The inference mechanisms consist of search and 
reasoning methods that enable the system to find 
solutions and, if necessary, provide justifications 
for its answers. There are two overall reasoning 
strategies — forward chaining and backward 
chaining. ! 

Forward chaining involves working forwards 
from the evidence (or symptoms) to the 
conclusions (or diagnoses). In a rule-based system 





it simply involves matching the IF conditions to the 
facts, possibly in a predetermined order. Forward 
chaining is easy to computerise and is suitable in 
cases where all the data is to be gathered anyway. 
Examples of such cases are where the data is 
generated automatically by an instrument and 
where a form has to be filled in. 

_ Backward chaining works from hypothesis to 
evidence. The system chooses a hypothesis and 
looks for data to support or refute it. It can be 
programmed in a recursive manner and in 
consultation-style systems typically leads to a 
more natural kind of dialogue. The problem of 
which hypothesis to pick in any given situation is 
not yet fully solved and so in practice most systems 
use a mixture of forward and backward chaining. 


THE ACQUISITION MODULE 


Experts are notoriously bad at saying how they 
reach their conclusions, not necessarily because 
they wish to preserve trade secrets but because 
many of their thought processes lie buried beneath 
the level of consciousness, at the intuitive level. So 
knowledge acquisition has come to be regarded as 
the main bottleneck in expert systems 
development. Experts tend to be good at criticism, 
however. They can look at an example case and 
say what decision should have been taken and, if 
required, criticise a computer’s suggested solution. 
A good deal of attention has therefore been 
devoted recently to developing software tools that 
allow an expert system to induce its own 
knowledge from _ pre-classified examples. 
Effectively, this power assists the knowledge 
acquisition process. Overcoming at the same time 
many of the difficulties of extracting knowledge 
from human experts and the laborious task of 
coding it for the computer. Even if the system 
cannot do the whole job — from a database of 
instances to a set of decision rules — on its own, it 
may be useful if it can refine its own knowledge 
base during a period of ‘apprenticeship’ or during 
use, learning from its mistakes. We will take a 
closer look at some machine learning systems in 
forthcoming instalments. 


THE EXPLANATORY INTERFACE 


One of the good things about Mycin, Prospector 
and many classic expert systems was that they 
could justify their conclusions on _ request. 
Obviously when the responsibility for life-and- 
death or even profit-and-loss decisions is being 
handed over to the computer it is essential for the 
system to explain its reasoning. Here is an example 
of how Mycin replies to a WHY? question posed by 
its user (who is a physician, not a patient, and will 
not accept diagnoses on trust without 
explanation). The dialogue starts by Mycin 
requesting data. 


Is meningitis a hospital-acquired infection? 

WHY? 

[2.0] This will aid in determining the organisms (other 
than those seen on cultures or smears) which might 


t& 


8 


Bi L _ 


be causing the infection. It has already been 
determined that: 

[21] the infection which requires therapy is 
meningitis, and 

[2.2] organisms were not seen on the stain of this 
pending csf culture, and 

[2.3] the type of infection is bacterial, and 

[2.4] neurosurgery is not one of the relevant items 
from the history of this patient, and 

[2.5] the age of this patient is greater than 10 days. 
Therefore, if: 


[2.6] the infection was acquired while the patient was 


hospitalised, 

then there is evidence that the organisms (other than 
those seen on cultures and smears) which might be 
causing the infection are e.coli (0.75), 
Staphylococcus-coag-pos (0.3), pseudomonas- 
aeruginosa (0.3), klebsiella-pneumoniae (0.5) 

— from [RULE 545] 


This explanation facility is in effect a partial trace 
through the program’s reasoning process, couched 
in medical-jargon English. Such explanations can 
be produced fairly easily and cheaply in rule- 
based systems (by regurgitating the rules being 
used and their predecessors), which is a point in 
favour of the rule-based encoding of knowledge. 
Notice that the conclusions have numerical 
weightings attached. These are in fact not true 
probabilities. They are weightings that allow the 
system to deal with uncertainty in a consistent 
manner, and come up with an ordered list of likely 
diagnoses in the final analysis. 


mand he. 


© Special 


ys 


0: 
Hs 


; | 


_ 


te 


. 
Hy 


COURTESY OF ICI PLANT PROTECTION UK DIVISION 


SSeS 


SSeS 





The Grain Brain 

Wheat Counsellor is an expert 
system developed by ICI and 
available to farmers, free of 
charge, on Prestel. The system 
is designed to advise farmers 
on methods to combat wheat 
diseases, the correct chemicals 
to apply and an estimate of the 
likely losses. Although the 
system is designed to simulate 
the type of conversation that 
might be held over a farm gate, 
its knowledge has been 
accumulated from scientific 
studies of the spread of crop 
diseases. In order to gain the 
information from which it will 
draw its conclusions, the 
system leads the farmer through 
a series of simple questions. Its 
advice is then given in the form 
of a list of the treatments 
available, together with a 
suitability rating for each 
treatment: 


THE HOME COMPUTER ADVANCED COURSE 1303 











EXTENDED VIEW 





So far in in 1 our series Dr n CP/M w we e have concentrated 
primarily on looking at the command structure of the 
operating system. We turn our attention now to the 
files upon which CP/M commands operate and how 
they can he manipulated within the system. 





We have already discussed file extensions in CP/M, but 
-  let’snowlookatthem in greater detail. As we have seen, a 

_ CP/M file consists of a primary name, which can contain 
up to eight characters, followed by a full stop and up to 
three letters, constituting a file extension (although this 
may be omitted). You can theoretically add any extension 
onto the primary filename, butsome of these are reserved 
for specific purposes. For example, the COM extension is 
reserved for CP/M COMmand files. This informs CP/M 
that a file with this extension is to be added to the list. of 
transient commands that can be run under it. 

Similarly, Basic programs written under CP/M qin 
be stored with the file extension .BAS. Many versions of 
pasic that run under CP/M will automatically assign this 
~ extension to a sasic file, eliminating any need for you to 
type it in. Although the Basic program will be stored as a 
source (text) file, the difference between this file and an 
ordinary text file is that when the program is reloaded 
prior to being run, CP/M will tokenise the Basic program 
rather than list it as an ASCII sequential file. However, 
many machines will compile their sasic programs before 
running them. Files that are compiled before execution 
will be stored with an .INT extension. This means that 
they are INTermediary files consisting of object code. 

Machine code programs, like Basic programs, can also 
have several different extensions assigned to them 
depending on their status. When we write a program in 
Assembly language, the source listing should have the 
extension .ASM attached. If the program does not have 
the correct extension, the resident assembler will not 





1304 THE HOME COMPUTER ADVANCED COURSE 





attempt to assemble the program am will simply 
generate a file error. 

When we attempt to assemble the program, we must 
select one of two extensions. These are either .HEX or 
PRN. The HEX extension means that what is produced at 
the end of assembly will be a HEXadecimal object file. 
Alternatively, with PRN the assembler will also produce a 
printed listing of the assembly with a copy of the source 
listing, the object code, the addresses of each of the op- 
codes and the list of assignments along with a list of 
errors. Thus, the PRN extension provides an essential aid 
in debugging assembly programs. 

The final group of file extensions we shall look at are 
those associated with text files. Many versions of CP/M 
have a small text editing facility (called by executing the 
command file ED) provided within the operating system 
itself, whereas others assume you will have a specialised 
word processing package that can be run under CP/M. 
However, regardless of which you may be using, the file 
extensions remain the same. 

Apart from the reserved filename extensions that have 
already been mentioned, almost any three letters can be 
used as an extension. In fact, you do not have to add an 
extension at all. If a text file is SAVEd without an extension 
having been added, CP/M will often add its own. For 
example, the TEXTED utility will add the extension .TXT 
on the end of a file whereas WordStar will add .SSS. 


BACKUP FILES 


lf you look atthe directory when atextfile has been SAVEd 
you will notice that two files have been created: one with 
the file extension you have added and one with the suffix 
.BAK. This is a built-in safety feature of CP/M. Obviously, 
it is vital that important documents are not accidentally 
deleted or corrupted, so to prevent such disastrous 
occurrences CP/M will create two copies of all text files: a 
normal file and a backup .BAK file. 

Thus, if you accidentally ERAse a file when editing, the 
backup version will always be available so that your 
previous work will not be irretrievably lost. When a file 
has been edited and then reSAVEd, a new version of .BAK 
will also be created. Itis therefore a good idea to regularly 
reSAVE files so that the backup copy will be kept up to 
date. 

Despite the fact that it is not necessary to add 
extensions, once implemented they are a useful aid in 
organising your files; not only for your own benefit — for 
displaying information about the organisation of files and 
headings — but also for the manipulation of groups of 
files. One of the most useful of these manipulations 
involves the use of ‘wildcard’ characters, which enable 
‘fuzzy matching’ of files. 

Suppose, for example, that a managing director has 
written a number of memoranda in the month of July. 
Sometime later he may decide these files are out of date 
and no longer needed in his catalogue. To delete July's 




















memoranda, he could, of course, go through the 
catalogue and delete each of the files individually using 
the ERA command, but if there are a large number of files 
this could be a long and tedious process. 

However, providing he has had the foresight to give all 
July’s memos the same file extension, say .JUL, this 
process could be performed with a single command: ERA 
D:*.JUL (where D is the optional drive name). Placing the 
asterisk before the full stop tells CP/M to ignore the 
primary filename and ERAse the files with the JUL 
extension. This asterisk can also be used on the right of 
the full stop. Using asterisks on either side of the full stop, 
the command will erase all the files on a disk, such as 
ERAS. 


SELECTIVE FILE DELETION 


Let’s assume that the managing director keeps all July's 
files with the suffix JUL. We shall now complicate 
matters by also assuming that there are a number of 
important documents that he does not want to delete. In 
this case it is out of the question to use the * prefix, since 
this would erase July’s important files along with the 
redundant memos. However, our managing director has 
distinguished his memoranda from other files by naming 
them MEM1.JUL, MEM2.JUL and so on. However, it is 
still possible to delete all the memoranda with a single 
command without accidentally deleting other files, in 
which case executing the command ERA D:MEM?.JUL 
would be appropriate. Here, the operating system is 
being told to delete all files beginning with MEM and 
ending with the suffix .JUL. The ? in the fourth position 
signifies to CP/M that the fourth character is not 
significant and may be ignored. 

This process can be adapted for any of the 11 possible 
positions in afile name. Itis particularly useful should our 
managing director wish to delete memos for both JUNe 
and JULY, since both sets could be replaced by the format 
MEM?.JU?. Combinations of * and ? can appear ina file 
name so that ERA D:???7Q???.* would erase all files 
with a Q in the fifth position of the prefix. 

Use of the wildcard characters * and ? is not confined 
to the ERAse command but can also be used with, among 
others, the PIP, STAT and REN commands. Hence, in 
order to transfer a number of files from one disk to 
another, a typical command would be PIP B:=A*.”. This 
command will find all the files on drive A that match the 
format (which in this case would be all of them) and copy 
them onto the disk in drive B. In this way we can use 
wildcards to copy the entire contents of one disk to 
another. 

Thus far in the series we have looked at commands 
that are used to control CP/M. However, the operating 
system also makes extensive use of control characters to 
perform many of its operations. Perhaps the most useful 
and common control character is the CTRL-C 
combination. Pressing these characters will produce a 
‘warm boot’ to the system and reload CP/M into the 
computer. This is important, not just when reloading CP/ 
M after a system crash, but also when inserting a new 
disk into one of the drives. 

Remember that CP/M keeps a copy of a disk’s ‘log’ in 
the computer's memory. When we exchange disks in a 
drive the operating system must be informed of the 
change, otherwise it may generate errors. When wewarm 


boot CP/M, it will re-log the contents of each disk drive, 
which will enable us to continue. CTRL-C can also be 
used to halt the execution of many progams, since CP/M 
will automatically interrupt the system while it resets 
itself. 

Many of the other control characters are concerned 
with editing text and have been adopted by a number of 
word processors that run under CP/M. For example, 
CTRL-H will delete the last character, whereas CTRL-U 
and CTRL-X will delete an entire line. If a printer is 
connected, text can be sent to it by typing CTRL-P. 
Pressing CTRL-P a second time halts this operation. 

Other control characters are used in CP/M, many of 
which have been rendered obsolete by advances in 
hardware and software. There are several reasons why 
these characters have been retained even though their 
functions appear to have been duplicated by other keys; 
for example, most home computers now have a Delete 
key fitted. Part of the explanation is historical. Many early 
microcomputers did not have a Delete key or cursor keys, 
so that screen editing facilities had to be incorporated 
within the operating system. 

Another reason for retaining the system is that of 
compatibility. While the CTRL and alphabetic characters 
have retained their ASCII equivalents over the years, the 
newer keys may not have, and so the control characters 
have remained to retain compatibility. Finally, a user who 
has spent several years with CP/M will have grown 
accustomed to using these keys. Altering the system now 
would mean that he would haveto relearn control from the 
beginning. 

Having finished our brief overview of the commands 
and files as implemented on CP/M, we can now carry out 
most of the everyday functions used within the operating 
system. In the next instalment, we'll delve deeper into 
CP/M to see how it is constructed and how the program 
interacts with the computer and its peripherals. 


LIZ DIXON ON THE MACINTOSH 


Walk On The Wild Side . 
The use of ‘wildcard’ characters 
is an important feature of CP/M. 
By entering ‘wildcards’ at 
different positions, the 
computer will effectively ignore 
any characters in that position 
when searching the directory. 
This means that by careful 
allocation of filenames the user 
can manipulate whole lists of 
files which are classified under 
different headings 





THE HOME COMPUTER ADVANCED COURSE 1305 








We complete our digital tracer project b 
giving the second half of the tracer program 
for the BBC Micro. Adding this to the listing 
given in the previous instalment provides the 
user with an alternative method of enabling 
the tracer to produce points, lines, circles 
and filled triangles. 


The second part of the tracer program controls the 
use of the tracer in an ‘elastic mode’. Rather than 
simply fulfilling a freehand drawing function, the 
tracer can be used, when elastic mode is selected, 
to specify the start and end points of a line, the 
centre and radius of a circle, or the three corners of 
a filled triangle. Selection of each of these 
functions, together with a point-plotting fuction, is 
made by pressing the appropriate keys from the 
menu displayed at the top of the screen. Save, 
Load and Clear screen functions, similar to those 
for the freehand mode outlined in the previous 
- instalment, can also be selected from this menu. 
The new section of program given here, therefore, 
allows complex patterns to be created simply on 
the screen, using the tracer and a few simple key- 
presses. These patterns can be saved to disk or 
tape to be reloaded later. 


THE FOUR PROCEDURES 

@ PROCpoint 

Calling PROCdraw (a procedure given in the first 
half of the program) with togflag set to one 
provides us with a simple way of moving the cursor 
around the screen without drawing lines. Setting 
togflag to one ensures that pen-up mode is selected 
before the procedure is called. This call is placed 
within a loop that also looks for a keypress that 
might terminate the loop or be used to change the 
foreground colour. In addition, if the tracer button 
is pressed then a point is plotted in the current 
foreground colour at the current cursor position. 
In order to stop double presses, the procedure 
cannot continue after a button press has been 
detected until the button is released. 





@ PROCline 

The first action of the procedure is to store the 
current cursor co-ordinates, as these will be used 
to locate the fixed end of the elastic line. The 
cursor is then erased and a line drawn to a point 
corresponding to a new cursor position. This is 
drawn in Exclusive-OR plotting mode, using 
GCOL3. Redrawing this line again later will erase it 
and restore any background ‘data to its original 
condition. Placing these two drawing actions 
within a loop allows the user to try out various line 


1306 THE HOME COMPUTER ADVANCED COURSE 











q 
: 





’ 
} 
/ 
: 





positions, as though the line were an elastic band 
attached at one end to a fixed point and at the 
other to the tracer’s screen cursor. When satisfied 
with a line’s position the user can ‘fix’ the line by 
pressing the tracer button or M on the keyboard. 
In this case the procedure omits to draw the line a 
second time, leaving it unerased, before returning 
to the main menu. 


@ PROCTill 

The fill procedure takes advantage of the BBC’s 
triangle-filling feature, accessed by using a PLOT 
85,x,y command. This command takes the last two 
points visited and the point specified in the 
command as the three corners of a triangle and fills 
the shape with a solid block of colour. The 
procedure uses a similar method to that used in 
PROCpoint to allow the user to plot the three 
corners of the triangle to be filled, using the tracer 
button. The last two lines of the procedure revisit 
the three points in order to fill the triangle shape. 


@ PROCcircle 

The final facility offered by the program allows the 
user to specify the radius of a circle using the same 
elastic band method as that used in PROCline. In 
fact, PROCline is called from within the circle- 
drawing procedure for exactly this purpose. Once 
the radius is selected control returns to PROCcircle, 
which must first erase the line left by PROCline and 
erase the cursor before drawing the circle. The 
circle’s centre will be held in x1 and x2, the cursor 
co-ordinates on entry to the procedure, and 
PROCline provides the co-ordinates of a point on 
the circumference, (x2,y2). Using these two points, 
the circle’s radius can be calculated and a standard 
circle-drawing algorithm used to create the circle. 

























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































Digital Tracer Program Part 2 


2350 
2360 
Zar 
2380 
press 
2370 
2400 
‘2410 
2430 
2440 
2450 
2440 
2470 
2480 
2490 
2500 














The following listing forms the 
second part of the digital tracer 
program for the BBC Micro. It 
should be added to the first part 
of the listing given on page 
1288 


DEF PROCelastic 

PROCelastic_inform 

REPEAT 

anst=INKEYSC1):1F ans#<¢>"" THEN PROCelastic_ 


togflag=1:PROCdr aw 

UNTIL exitflag=1 

ENDPROC 

DEF PROCelastic_inform 
PROCcalc_xy:0)ldx=x:oldy=y:PROCcursor(oldx,aldy? 
PROCreinform 

GCOL 0,1:MOVE 0,920:DRAW 1280,%20 

ENDPROC 

DEF PROCreinform 

PRINT TABC1,1);SPCC79) 

PRINT TABC1,1293;"S=Save L=Load M=Menu C=Clear 


R=Circle" 


2510 


PRINT" D=Draw Line 


P=Point F=Fili" 
ENDPROC 
DEF PROCelastic_press 


IF ans#="C" THEN CLS:PROCelastic_inform:ENDP 


IF ans$="M" THEN exitflag=1 
PROCcolour_change 
IF ans#="R" THEN PROCcircle_title:PROCcircle 


:PROCelastic_inform:ENDPROC 
L.2570 ,2600 


2570 
2600 


IF ans#="BD" THEN PROCline_title:PROC1ine 
IF ans$="P" THEN PROCpoint_title:PROCpoint 


Celastic_inform:ENDPROC 


2620 


IF ans#="S" THEN PROCsave_screen:PROCelastic 


_inform:ENDPROC 


2630 


IF ans#="L" THEN PROCload screen:PROCelastic 


_inform:ENDPROC 


2640 
2660 
2670 
2680 
2670 
2710 
2720 
2730 
2740 
2750 
2760 


ENDPROC 

DEF PROCpoint_title 

PRINT TABC1,19 SPCC79) 

PRINT TAB(15,1)>3;"Point Mode" 
ENDPROC 

DEF PROCpoint 

REPEAT 

togf 1] ag=1 :PROCdr aw 
ans#=INKEYS( 1) 

PROCcol our_change 

IF CADVALCOXAND 3)9<>0 THEN PLOT 69,x,y»:REPEA 


T UNTIL CADVALCO2 AND 3)9=0 


2770 
2780 
27970 
2800 
2810 
2820 
2830 
2850 
2860 
2880 
2890 
2700 
2710 
2920 
2930 


UNTIL ans#="M" 

PROCreinform 

ENDPROC 

DEF PROCline_title 

PRINT TABC(1,1>9 SPCC79) 

PRINT TAB(15,1>;"Line Mode" 

ENDPROC 

DEF PROCline 

x1=x:yl=y:REPEAT 
PROCcalc_xy:PROCcursor(ol dx ,oldy) 
x2=xiy2=y:GCOL 3,colour:MOVE x1,yx1:DRAW x2,y2 
anst=INKEY#¢ 1) 

IF CADVALCOXAND 3) THEN ans#="M" 
PROCcursor( x,y) :01 dx=x:o0ldy=y 

IF ans#<>"M"THEN GCOL 3,colour :MOVEx1,y»1:DRA 


W x2,y¥2 


2940 
2950 
2960 
2970 
2990 
3000 
3010 
3020 
3040 
3050 
3060 
3070 
3075 
3080 
3090 
3110 


PROCcolour_change 

UNTIL ans#="M" 

PROCreinform 

ENDPROC 

DEF PROCfil1]_ title 

PRINT TABC1,1> SPCC?9) 

PRINT TABC15,1)3"Fill Mode" 
ENDPROC 

DEF PROCfi11 

FOR I=1 TO 3 

REPEAT 

togf 1] ag=1:PROCdr aw: ans¢$=INKEYS$( 1) 
IF ans$<>""THEN PROCcol our_change 
UNTIL CADVALCODAND 3)<>0 

PLOT 69,x,y:x¢I=xiry(C Il =y 

REPEAT UNTIL CADVAL(COQ2AND32=0:REM AWAIT BUTT 


ON OFF 


3120 
3135 
3140 
3150 
3160 
3180 
3190 
3200 
3210 
3230 
3240 
3250 


NEXT I 

PROCcursor¢(x,y):REM cursor off 

FOR’ T=1 T@G=2:PLOT 694x011) ,rt( 1) tNEAT 1 
PLOT “83,x > 

ENDPROC 

DEF PROCcircle_title 

PRINT TABC1,1) SPCC ?9) 

PRINT TABC15,193;"CIRCLE MODE" 

ENDPROC 

DEF PROCcircle 

PROCI1ine 

GCOL 3,colour:MOVE x1,y¥i:DRAW x2,»2:REM RUBO 


UT LINE 


3260 
3270 
3370 
3380 
3390 
3400 
3410 
3420 
3430 
3435 
3440 


GCOL O0,colour:REM BACK TO NORMAL PLOT MODE 
PROCcursor(x2,¥2) 
radius=SQR¢(x2-x1)*2+Cy2-y1)*2) 
MOVE xltradius,y1 

FOR angle=0 TO 2*PI STEP Q.1 
rx=xl+tradius*COS¢angle) 
ry=yltradius*SINCangle) 

DRAW rx ,ry 

NEXT angle 

DRAW xitradius,yl 

ENDPROC 


THE HOME COMPUTER ADVANCED COURSE 1307 








The Plot Thickens 
There are two kinds of printer 
plotters — drum and flat bed. 
Although drum plotters are more 
common, the more expensive 
flat bed plotters, like the one 
shown here, are better for 
precision work. This is because 
the paper is held steady and the 
pen can be accurately 

~ positioned. Drum plotters are 
less accurate because the paper 
can slip on the carriage 


PET 


The Commodore PET, or Personal Electronic 
Transactor, represents one of the milestones in the 
development of the microcomputer. Its 
appearance in 1977 can be considered as one of 
the major events that directed computing beyond 
the realm of data processing departments and 
electronics enthusiasts towards the ‘dream’ of a 
computer in every home. 

The precedent established by the PET was that 
it was not only fully assembled with its own casing, 
but it also had a built-in cassette deck and monitor, 
as well as BASIC resident in ROM. You had only to 
plug in the machine and power it up in order to use 
it. Previously, microcomputers were available only 
as a kit or with minimal assembly at best. 


PICTURE PROCESSING 


Also known as ‘image processing’, picture 
processingis the digital analysis of signals supplied 
from a television camera or similar device which, 
after processing, can be displayed either on a 
television or video monitor or as a printout. The 
amount of detail displayed is a function of the 
definition (resolution) of the image, of which each 
point is referred to as a pixel. So, the greater the 
number of pixels there are within the picture, the 
higher the definition is said to be. 

The image received from the camera is held as a 
two-dimensional array within the computer. The 


individual pixels can be stored within the array ina 


number of different ways depending on the 
program used. At the simplest level, however, the 
information stored can merely state whether that 
pixel is on or off (whether or not light is falling on 
the corresponding point of the camera image). 
However, other information can be stored and 
manipulated within the computer, and this may 









1308 THE HOME COMPUTER ADVANCED COURSE 





specify colour or shades on the ‘grey scale’ (the 
relative contrast of the pixel compared with others 
in a monochrome image). 

Picture processing is finding an increasing 
number of applications in the television and 
satellite communications fields. These range from 
the stunning effects now being produced in films 
and videos to improving the definition of the 
sometimes hazy pictures received from space 
probes. Picture processing is also being applied in 
the field of artificial intelligence where it is used 
with the emerging techniques of pattern 
recognition. In this area the emphasis is not merely 
on programming a computer to produce a 
required display, but rather enabling it to interpret 
an image and attempt to understand its ‘meaning’. 


PLASMA DISPLAY 


The method of plasma display, which 1s 
increasingly being used in computers, is 
characterised by an orange or red light emanating 
from characters similar in design to those used on 
LCD displays. A plasma display is constructed by 
trapping a gas between two materials, one of 
which must be transparent (to enable you to see 
the display). At various points around the display, 
electrical lines are connected to form a matrix, so 
that when a current is applied to them, the gas will 
become charged and emit light. In this way, 
various combinations of currents through the lines 
can produce characters or designs. 

For the most part, plasma displays are made to 
produce single characters, although it is possible to 
build larger displays. However, the costs of these 
tend to be too high, especially since their functions 
can be performed just as well by devices 
incorporating cathode ray tube technology. 


PLOTTER 


A plotter is an output device that receives digital 
signals from a computer and translates them into 
graphical form, usually onto a piece of paper with 
a pen. The movements of the plotter can be 
directed along either the x and y axes, or else 
vertically, to raise and lower the pen. Of the two 
basic kinds of plotter, the first is known as a ‘flat 
bed plotter’, onto which a single piece of paper is 
laid. The pen is mounted on a bar that moves along 
one axis, while the pen itself moves along the bar, 
thus able to plot on any given point within the 
limits of the hardware. 

The most usual type of flat bed plotter consists 
of a board to hold the paper and moveable arms to 
position the pen, but a recent imnovation 
beginning to gain popularity is the robot, or turtle 
plotter. With these, the pen mounting travels 
freely over the paper on a motorised device. This is 
controlled by the computer, usually via a ribbon 
cable. Perhaps more familiar to home computer 
users, a drum plotter feeds a continuous roll of 
paper onto a drum, much like a typewriter. The 
pen mounting moves across the paper, along the x 
axis, while vertical movement, along the y axis, is 
achieved by the drum rolling the paper through. 


Sf A 











———4y- 























With its new 130XE micro Atari makes 
virtue of compatibility both with its XL 


predecessors and the familiarity of its 
graphics, sound and other features. What 
places it in a challenging position in the 
market, however, is its seductive styling and 
RAM capacity of a full 128 Kbytes, 


available at a very competitive price. 





Despite the fact that Atari was one of the early 
pacesetters in the home computer market, the 
early 1980s were not good years for the 
corporation. In 1984, after suffering heavy losses, 
it was taken over by the former head of 
Commodore, Jack ‘Tramiel, who set about 
reversing the fortunes of the ailing computer giant. 
His policy of marketing computer technology at 
the lowest possible price was soon evident in the 
shops when the prices of the 600XL and 800XL 
micros were dramatically reduced in time for the 
Christmas market. 

In itself, this move was not enough to reverse the 
trend. Atari was faced with a problem common to 
many computer manufacturers: low sales leading 
to lack of software support, which stifles sales even 
more — meaning that funds are lacking for further 
investment in new machines. 

It is wronic that Jack Tramiel was the person 





most responsible for placing Atari in this position. 
His aggressive marketing of the Commodore 64 
led to Atari being almost wiped out by its rival. By 
the beginning of 1985, the situation was changing 
dramatically. Commodore was faced with falling 
sales and the failure of its Plus-4 to make a major 
impact on the market, while Atari announced a 
host of new products. The first of the new 
machines is the Atari 130XE, a computer based 
around the 6502C processor. 

The 130XE is essentially the same machine as 
the basic Atari eight-bit computer, which has been 
around in one form or another since the beginning 
of the 1980s. The main difference between this 
machine and earlier Atari computers is the sleek 
new styling and the massive amount of on-board 
memory: the Atari 130XE boasts a full 128 
Kbytes of RAM. 

The casing of the computer looks very different 
from that of its predecessors. The light grey plastic 
outer shell has the elegant design the public has 
come to expect of a modern computer, with 
rounded lines and wide, sculpted keys that allow 
for ease of typing. The keys have a slightly better 
travel than that offered by previous models, with 
the added advantage of not rattling as you type. 

In common with the other 6502-based Atari 
micros, the 130XE has five pre-programmed 
function keys. However, unlike the previous 


CHRIS STEVENS 


Getting Back Into Shape 

The Atari 130XE is the first 
product to be launched under 
the company’s current 
president, Jack Tramiel. With 
128 Kbytes of RAM on board, at 
a price that compares favourably 
with many computers with only 
half the memory, Atari hopes 
that this will be the machine that 
will revive the company’s 
fortunes 


THE HOME COMPUTER ADVANCED COURSE 1309 





models, these have been placed above the main 
keyboard rather than on the right-hand side. They 
are now moulded in the same grey plastic as the 
rest of the casing and are designed in the stylish 
form of parallelograms rather than squares. ‘These 
are a great improvement on those of the XL series, 
which were metal and had a distinctly unsure and 
wobbly feel. 


INTERFACE CONNECTIONS 


The interfaces fitted on the rear and right-hand 
side of the new Atari also hold few surprises. On 
the side are the expected nine-pin D-type 
joystick ports first used by Atari and since adopted 
by almost everyone else. At the back of the 
machine is the 13-pin serial control port that 1s 
used by Atari to fit and daisychain Atari 
peripherals such as cassette decks, disk drives and 
printers. To the right, set into the casing, are the 
cartridge and expansion interfaces. The cartridge 
port enables the machine to run the large quantity 
of highly rated Atarisoft games cartridges, such as 
Pacman and Galaxians, that have been one of the 
strengths of the company over the years. 

The expansion port, however, is something of a 
departure from the previous standard. Earlier 
Atari computers had a 50-way edge connector as 
an expansion bus. The new machine has a much 
smaller 14-way bus fitted as a cartridge connector. 
The remaining interfaces on the 130XE are the 
composite monitor socket, an RF jack plug for 
television sets and the standard Atari power- 
supply socket. 

To keep costs down the 130XE has no on- 
board modulator to allow it to work effectively 
with British standard televisions, but has the US 
standard instead. Thus, to allow UK sets to be 
used, the aerial lead from the computer to the 
television runs via a small box that modifies the 
signal into one that will correctly process the 
television display. 

Styling and compatibility are all very well, of 
course, but Atari applied these to the XL series 
without conspicuous success. What makes the 
130XE different from earlier machines and what is 
its obvious selling point is the availability of a large 
memory capacity at such a low price. An eight-bit 
microprocessor can, of course, address only 64 

Kbytes of RAM at a time. To address twice that 
amount the computer has to make use of the 
process known as ‘bank switching’. Using this 
technique, the computer can look at a ‘window’ of 
64 Kbytes among the total 128 Kbytes. While the 
technique is not perfect, and although the extra 
instructions necessary to switch from one bank of 
RAM to another result in somewhat slower 
retrieval speeds, it does allow an eight-bit micro to 
address more memory than would otherwise be 
possible. 

Actually, the bank switching technique is more 
common than you might think. Both the Oric 
Atmos and the Commodore 64 have more than 
the normal complement of 64 Kbytes on board, 
and both use bank switching as a means of making 


1310 THE HOME COMPUTER ADVANCED COURSE 


Expansion Port 

The single departure of the 
130XE from previous Atari 
peripheral ports is the 
expansion slot 


RF Socket 

The 130XE RF control is 
configured to the US standard. 
Therefore, the aerial lead is 

fitted with an additional box 
which contains the logic to 

conform to the UK standard 


RAM Chips 

The 128 Kbytes of RAM are 
stored in these two banks of 
8- Kbyte chips 


Memory Control Chip 
Memory management and 
bank switching routines are 
contained in this new chip, 
which has been christened 
‘Freddy’ 


Graphics Chips 

The ANTIC and GTIA chips 
control the computer's screen 
graphics 


CPU 

Like all previous Atari 
machines, the 130XE is based 
around the 6502 processor 











Cartridge Port 

The cartridge port enables the. 
computer to take advantage of 
the wide range of Atari 
software 














Peripheral Port 


interface 


Joystick Ports 





PIA Chip 
input/output control is 
managed by a 6520 chip 


Sound Chip 
The ‘POKEY’ chip is 


sound capabilities of the 
130XE 





Atari peripherals, such as disk 
drives and printers, can be 
daisy chained together with 
the computer via this serial 


The computer is fitted with a 
pair of joystick ports which, 
naturally, are Atari standard 


responsible for the four octave 


full use of the available memory. 

What is unusual is the price of the 130XE. 
Although more expensive than the Sinclair 
Spectrum and Acorn Electron, the 130XE is 
considerably cheaper than the list prices of the 
BBC Micro and the Commodore 64. In order to 
provide a 128 Kbyte computer at that price and 
produce a profit, Atari needs to have cut 
production costs considerably. To an extent, the 
nature of the machine itself will have kept the price 
low: the 130XE is essentially a revamped 
machine, which means that development costs 
have been kept to a minimum. The main 
economies have taken place inside the machine. 


CUTTING COSTS 


The memory area comprises 16 eight-Kbyte RAM 
chips. The production cost of these chips, which 
are no longer considered the product of ‘leading 
edge technology’, has fallen dramatically in the 
past few years and this is reflected in the price. 
Another way of reducing costs is to keep the 
number of components on the board to a 
minimum. Although many of the chips on the 
earlier XL series have found their way into the 
130XE in order to maintain compatibility, the 
printed circuit board is exceptionally well laid out, 
looking considerably less cluttered than many 


machines with only half the memory capacity. - 


Finally, Atari has invested heavily in automated 
assembly plants, of which the 130XE is the first 
product. All the components on the board are 
soldered on by machine. 

As none of the sound, graphics and Basic ROM 
chips have been altered in essentials, the computer 
is, for the user, exactly the same as the earlier 
models, with the high-performance sound and 
graphics with which Atari has become associated. 
One major change of benefit to the user is the 
manual. The handbooks that came with earlier 
models tended to be oversimplified to the point 
where they appeared to be aimed at children. The 
BAsic tutorial is much improved and the company 
has given some technical specifications in the 
appendix. However, for a fuli explanation of the 
dialect, one still needs to purchase the Atari BASIC 
Reference Manual. 

Although the Atari range of micros was sorely 


in need of upgrading, the arrival of the 130XE is 


something of a puzzle. The extra 64 Kbytes of 
RAM provide a lot more memory for the 
programmer and yet there are no programs 
available as yet to take advantage of it, even 
allowing for compatibility with the Atari software 
already on the market. Normally, one would 
expect the launch of such a machine to be a 
preliminary manoeuvre before a serious thrust at 
the small business market. However, the new 
Atari management has consistently denied any 
such intention. Perhaps the real reason for the 
launch of the 130XE is that Atari intended to pre- 
empt the launch of the Commodore 128, a 
Commodore 64 compatible machine that also has 
extra memory but is priced much higher. 





ATARI 130XE 


£169.95 inc VAT 
350 x 233 x 63mm 


6502C running at 1.79 MHz 





128 Kbytes of RAM, 24 Kbytes of 
ROM 


40 x 24 text display, 320 x 192 
pixels (high-resolution) with 256 
colours available 





Cartridge port, TV jack, composite 


_ monitor socket, two joystick ports, 


serial input/output port, 
expansion interface 


Atari BASIC, LOGO, FORTH, PILOT 





62 keys, including five pre- 
programmed function keys 


The manual gives a full 
explanation of Atari BASIC, 
although the tone is still rather 
oversimplified. Explanation is 
given in the appendix of the 
interface configurations and how 
to ‘bank’ the other 64 Kbytes of 
RAM 





“The 130XE has the advantage of 


being able to trade on Atari’s 
traditional strengths, yet 
possesses an additional 64 Kbytes 
of RAM that can be used as a 
‘silicon disk’ for fast storage and 
retrieval 


- The computer does not solve 


Atari's basic problem of lacking a 
large third-party software base. 
The fact that the 130XE is 
essentially a revamped version of 
a machine that has been around 
for some years may mean that it 
will not generate the interest in 
customers that the company 
needs 


THE HOME COMPUTER ADVANCED COURSE 1311 








~ SEARCHING 


LOOKS 


The flow of program control in 
PROLOG does not follow the 
familiar sequential pattern used in 
languages such as BASIC and 
PASCAL. We discuss PROLOG’S tree- 
like search procedure, highlighting 
the general steps between defining 
a program’s objective and 
achieving it. 


- While languages like Basic and PASCAL 
have sequential flows of control, with 
control passing from statement to 
statement in strict top-to-bottom order 
(unless a loop or a GOTO interrupts it), 

| the flow of control in proLoG takes the 
form of a depth-first search through the 
program clauses. 

To understand this more fully, think 
of the program as a tree, with the goal 
(proposition) to be proved at the root 
and all the sub-goals as choice-points 
where the lower branches divide. There 
are many ways to search a tree like this 
but the method used by PROLOG is to 
take the leftmost branch and follow it 
down as deeply as possible. As it tries 
each branch, it marks its trail, and when 
it reaches the bottom and can go no 
further, it backs up to the nearest 
choice-point, taking the leftmost 
branch that it has not already taken, 
and carries on down from there. In this 
way, the system will eventually explore 
every path through the tree and thus 
will have tried every possible way of 
proving the topmost goal. 

An exhaustive depth-first search is 
guaranteed to cover all paths, but could 
be a lengthy business. In fact, PROLOG 
manages to save itself some work. A 
PROLOG Clause Is, aS We Saw in Our 


queue(X) 


previous instalment, a rule which says 
that the head goal is true if all of the 
subgoals are true: 


goal:— subgoal1,subgoal2,subgoal3. .. 
etc. 


and so on. This is probably more easily 
understood if we write it as: 


IF subgoal! is true 
AND subgoal2 is true 
AND subgoals is true 
AND etc. 

THEN goal is true. 


Because the subgoals are ANDed 
together, the whole clause will fail if 
any one of them cannot be proved. So 
PROLOG works through the subgoals 
from left to right and, if it fails to prove 
one, will stop at that point and not 
bother with the rest. 

Backtracking can make programs 
behave in a way that makes the order in 
which the code is written almost 
irrelevant. However, the advantage is 
that the flow of control, instead of 
being a major concern as it is in BASIC, 
has only a minor importance, leaving 
you to concentrate on the logical 
structure of your problem. 

The emphasis that PROLOG places on 
a ‘declarative’ statement of the problem 
does not mean that you cannot see 
your programs as behaving 
procedurally. The pRoLoc clause: 


martian(X):— no. of limbs(X.7), no. of 
heads(X.2), can program in(X,cobol). 


can be read declaratively as: ‘X is a 
martian if X has seven limbs, two heads 
and can program in CoBoL’. Its 
procedural reading would be: “To 
prove that X is a martian, first prove 


1312 THE HOME COMPUTER ADVANCED COURSE 





Question Time 

This flow-diagram shows 
PROLOG in action, answering a 
simple query posed by the user. 
Note that the variable X is given 
two different values during 


program execution, yet each 

value is retained. This is 

possible because PROLOG e 
treats variables as local to each 

separate invocation of a clause 


that it has seven limbs, then prove it has 
two heads, then prove it can program in 
COBOL’. 


LISTS AND RECURSION 


PROLOG 1s not as strongly ‘typed’ as 
most other languages. Nor is it fussy 
about the data types of arguments 
within its terms. So the term 
pred(Argument) could be used at 
different times with the variable 
Argument set to an integer, an ‘atom’ 
(such as marty, venusian, d24, and so on), 
or a list. However, PROLOG treats its 
data types in different ways, allowing, 
for instance, numbers to be 
arithmetically manipulated. 

Anyone familiar with LoGo or LIsP 
will have come across the list data type 
before and the special ways that are 
used for manipulating lists. A PROLOG 
list is written enclosed in square 
brackets with the list elements 
separated by commas. So 
[apple, pear, banana] is a list of fruits, 
[a,f,e,g,1,X] 1s a list of letters and so on. 

To get inside lists, PROLOG lets us take 
them apart one element at a time by 
removing the first element. The 
notation [Head | Tail] describes a list with 
the element Head and the rest of the list 
in the list Tail. Applying ‘I’ to our list of 
fruits will give us [apple | [pear,banana]]. 
As you can see, lists can have other lists 
as members. As a special case, if we 
take the list [280] with one element and 
break it up with |, we get [z80 | []]. The 
list in the tail is [], which represents the 
empty list. 

PRo.oG allows recursion, which, in 
fact, is the normal style for a PROLOG 
program. A recursive definition is one 
that defines something in terms of 








Lila 


itself. In PROLOG, we might write: 


queue([person)]). 
queue([person | X]):— queue(X). 


When we have two or more clauses, as 
we have here, which have the same 
head, they are known as a procedure. 
The queue procedure has a clause 
defining a queue as a list having one 
element, person. It then has a second 
clause informing us that a queue could 
also be a list with the element person at 
the head and with a list called X as its 
tail. We then see from the right-hand 
side of this clause that X must itself be a 
queue. 

If we give PROLOG a goal such as: 


queue([person, person, person)]). 


asking it to say whether the list 

[person, person, person] is a queue, it first 
looks for a clause in its database to 
match our goal. The first one it will find 
is queue([person]). This does not match 
because the lists are not identical, so it 
will scan down to the next clause: 
queue([person | X]):— queue(X). This 
does not match either and it fills in the 
values of the variables like this: 


queue([person | [person,person]]):— 
queue([person,person)). 


To show that the head goal is true, it 
must show that the subgoal is true. So 
PROLOG takes queue([person,person]) as 
its goal and begins scanning down the 
clauses from the top to find a match. 
Again, queue([person]) does not match, 
but the second clause does, giving: 


queue([person | [person]]):— 
queue([person]). 


An important point to note here is that 
the variable X, which on the first run 
through was set to [person,person], has 
now been set to [person]. Yet the first 
value of X has been retained. 

This is possible because variables are 
local to each separate invocation of a 
clause; thus every call to queue([person | 


X]) can be thought of as using a separate 





and unique variable. In PROLOG, there is 
no such thing as a global variable. 
Having matched the head of this 
goal, to prove it we need to prove the 
subgoal on the right of the :— symbol, 
which is queue([person]). Another scan 
of the clause-base is begun and this 
time a match is made with 
queue([person]), which succeeds straight 
away and means that 
queue([person, person]) (our previous 
goal) is now shown to be true. This in 
turn means that queue([person, 


person,person)), the original goal, is true. 











KEVIN JONES 
The queue procedure shows us a | | 
number of important things about 
PROLOG. For instance, the ordering of 
the clauses can be crucial. (Try placing 
the two clauses in the opposite order 
and see what happens when you try to 
prove a goal.) It also illustrates how 
giving extra clauses is the same as 
giving alternative ways of proving a 
goal, just as if we had used a logical OR 
between the clauses. This means that 
PROLOG does not need an OR operator 
— although most implementations 
provide one. 


KEVIN JONES 


THE HOME COMPUTER ADVANCED COURSE 1313 





The final instalments of our New World 
simulation game project are devoted to 
considering the Basic flavours that will allow 
the game to run on the Spectrum, the BBC 
and the Amstrad micros. This article focuses 
on Spectrum flavours and includes the first 
section of the complete common listing. 





The program was written on the Commodore 64 
but uses minimal Basic where possible. Problems 
in converting the program to run on the Spectrum 
lie in two main areas: first, the Spectrum will allow 
only single-letter variable names to be used with 
arrays or FOR... NEXT loop counters. We provide a 
conversion table here. Second, Spectrum string 
handling is unusual in that LEFTS, RIGHTS and MIDS 
are not available, although each has a Spectrum 
equivalent. Spectrum owners should refer to the 
flavours given with each module for these 
conversions. In addition occurrences of PRINT 
CHRS(147) should be replaced by CLS and lines that 
wait for keypresses of the form: 


<line no> GET IS:IF IS=“” THEN <line no> 
should be replaced by: 


<line no> LET IS=INKEYS:IF IS=“” THEN GO TO 
<line no> 


In the next instalment we will give the second 
section of this full program listing. 





1314 THE HOME COMPUTER ADVANCED COURSE 


ae 





Bisa | “Sasa 





BOSUBS 248 
FORT=17TUS 


Ch i. 
tin & & 
mS it} 


TFORS La =1THENS#="BOTTLE OF MEDICINE #":GOTO?735 
S$="BOTTLES OF MEDICINE*" 
PRINTOARS 13: :GOSUB?1h6 

GOSUBP2H8 

IFOAS 2)=8THEN 736 

TFOAC 2)=1THENS#="GUNe" :GO0TOr45 


oJ oJ J ~J 


ba IFCCS T =H T HENS a 
S50 PRIBITELC TD s 
446 PRINTCECT2 : 
S62 IF CECT ISLTHENPRINT" "“:GOTO46S8 
S64 PRINTS" 
4438 GOSUB?2H 
3° NEXT 
474 GOSUBS2H4a 
475 PRINT: S¢="AHO THE FOLLOWING FROWISIONS:s":G08u 
Bia 
S56 GOSUBPSAA 
S85 FPORTS=i 7o4 
S54 ITFRAtTI=s8 THEN 714 
S75 PRINTPACT) :US¢T):"S OF ": 
FRR PRIPITRSCT 3 
*HS GOSUBS2aG 
71H NEXT 
f1S GOSUBS2H4u 
fe PRINT: S#="YOU HAVE ALSO GOT:#" :GOSUBS1 44a 
f25 GOSUB?2a8 
YSh [TFOAC 1 =a8THEN?4a 

aS 
B4 

5 

& 

A 

3 


jm 


‘ St=" GUNS" 

& PRINTORS 2); :G0SUB71 68 
e GOSUB?2H8 

é TFOARS S)=8THEN Sse 


~] 


TFOR*« 33=1THENS#t="BAG OF SALT#®":GOTO?SS 
S$="BAGS OF SALT®=" 
PRINTOAt 333 :GOSUB?1 48 

GOSUBS 246 

TFOAR! 4)=8@THEN? 7a 


1 Som 


of Oo ICN inion et hee Bb i to 


hein eb oi Sm Opi eo on tt 


=. 


e TFOR¢ 4¢=17THENS#="BALE OF CLOTH*" :GOTOFS5 
764 St="BALES OF CLOTH#" 

fé5 PRINTOAC 4S) ;:GOSUBS1 668 

#64 GOSUBS24H 

f?@ TFOAtSI=8THEN? Se 

?fS ITFOAtSI=1 THENS#="KNIFE®" :G0TO?F 75 

ff4 St="KNIVESS" 

??S PRINTOACS) ;:GOSUB?1 Aa 

fe é GOSUBS2b8 

#88 ITFOAt6)=6THEN? 74 

PSS LFOARC 4)=1THENS#="JEWEL®" :GOTOFSsS 

@S4 S¢=" JEWELS*" 

°S5 PRINTOAC 69; :GOSUBS1 ab 

786 GOSUBS2H4 

°F GOSUBS 244 

??2 PRINT:PRINT" YOU HAVE "“sh0O:" GOLD PIECES LEFT" 
@?6 GOSUBS2h48 

??? St="PRESS ANY KEY TO START VOYAGES" 

“78 GOSUBS1 48 

2? GETIS:1F Il¢=""THENF SS 

SHB WT=6 :REM ZEROISE WAGE TOTAL 

S61 HE="N" :REM HALF RATION INDICATOR 

S862 DIMHR( 4) :HROLI=1:HR¢ 2)=1:HR¢3)=1:HRi43= 





Wk 1 

GOUSUB4SHBH: REM CREW STATUS REPORT 

GOSUB42@6:REM PROVISIONS REPORT 

BOSUBS3H8:REM OTHER GOODS REPORT 

GOSUBF 208 :PRINTCHRS: 1473 

FRINT: PRINT :PRINT 

S43 S8="IT 15 ESTIMATED THAT THE VOYAGES" :GUSUB?1lUa 
S44 PRINT"WILL TARE A FURTHER" :INT¢ JL-WkK+1): "WEEKS" 
B45 GOSUB? 26H 

846 PRINT: S#=K#:GOSUB?S1 aa 

S47 GETIS:1IFI¢=""THENS4? 

854 GOSUBSHBH:REM CHECK WAGE BILL 

855 GOSUBSi6H: REM ISSUE RATIONS 

$66 GOSUBSShb 

61 REM GO TO GENERATE RANDOM EVENTS 

GOSUBSS8@:REM GOTO MAJOR CONTINGENCY 

IFHR* S9=.5ANDRND¢1)¢. STHENPRINTCHRE( 147) :GOSUB 


J 
= 


ee 


pica 


REM ALBATROSS IF SHORT OF MEAT 
GOSUBZ 2H 

GOSUB S36: REM ENOG-OF-WEEK REPORT 
WIKSLIK +1: 0FWK <= JLTHENS 25 

REM ARRIVAL AT NEWWORLD 

GOSUB1 Gb 

GOSUBIaB Ta 

GOSUBIaSHE 


GOSUBIGSHEe 


“J 7) oS 


00 oO 
Oh Whee eA © co on on 


“oo 0 oo 0 oo CO co oo a 


“Oo ~O MO ~O 


END 





1@8@ PRINTCHR#(147):PRINT" STAGE 1 - HIRING CREW" 
141@ PRINT" ---------------------- ‘ 

i@i2 PRINT 

1815 GOSUBSza4 








SIMULATION GAME/PROGRAMMING PROJECTS 


PRINT: PRIWT"CRELD TrPES GUSILGABLE:" 
GOSUB? 2a 

FPRICT 

PRINT" TYPE DESCRIPTION WAGES PER WEEK" 
PRIWT"---- ----------- -—----—---—----—-—-— " 
FRIMT " SAILOR 
PRINT " DOCTOR 
PRITIT " MECHANIC 
PRItHT" HALT GATOR 
FPRICIT" Cook 
GOSUB? 2H 

PRIWT PRINT :PRIWT 
St="ENTER CRE TYPE RPEQUIRED( 1-5) #" :GOSUB?1 46 
li2e Sé#="CF “F° TO FINISH HIRING*" :GOSUBS1 ab: PRINT 
:INFPUTIS 

1125 ElSURLt lS) 

1i28 [FLEFT#¢ 1,1 .="F"THENPRINT:FRINT"“EMD OF CREM 
HIRE." :GOSUBS2h6:G0TO1 Siu 

1138 IFCT?}0ANDCT<4THENI 156 

liso PRINT PRINT 

1146 PRINTI#¢;:S¢=" IS NOT A CREW TYPE®" :GOSUB?1 64H 
1142 GOSUBS266 

1145 S#t="FPLEASE ENTER AGAIN" 

1146 GOSUBY146 

li4? GOTO1 S66 

1156 PRINT: PRINT 

11355 CN=CN+1:REM CREW HIRED SO FAR 

1156 TS*CN,12=AT:REM CREM TYPE 

115” TS¢CCN,2)=196:REM STARTING STRENGTH 

1158 WSLIT+WG0CT3 : REM TOTAL WAGES 

115% COCCTISCOCCT3+1:REM CREW TYPE COUNT 

i146 St="CREL SO FAR:" 

1178 FORT=i1TU5S 

LiS@ PRINIS#:Clito;" “Ceca; 

1185 I[FCCCT) F1ORCCeTISe8THENFRINT"S" :GOTOLIS= 

L188 PRINT? & 

liss S¢=" . 

live NEXT 

11735 FRINT: PRINT"TOTAL WEEKLY WAGE BILL ";LIT 

1266 TFCH=CM-1THENPRINT :S¢="0NLy ONE MORE CREWS" :6 
OSUBFIBE :GOTOL2S5 

1262 TFCN=CMTHENPRINT :S¢=" 
UBS1 ae :G0TO1L S16 


Si MS mH 


“Jo. Uf ts ba bl ni 


Woo LA mm Hm em me LA ee 


GOLD PCS" 
GOLD PCS" 
GOLD PCS" 


ms he he 
Cy oS on on em 


Peep 
Oh fe fo hae 


Ss et Eom 


Moe @ ow 


— 
— 


SHIP WOW FULL! I" sG0s 


l27o REM 

1366 GOTO1L815 

Tsl6 PRINT: S#=k¢:G0SUBS1G8:PRINT: GOSUBS 24 
1326 GETI¢:1TFIS=""THENI S26 

17? > RETURN 

2606 PRINTCHRé( 147) 

2618 S¢=" STAGE 2 - PROVISIONINGs" 

2615 GOSUB?I OG 

2620 S¢=" ----- ee a 

2025 GOSUBS1aa 

2636 GOSUBS200:PRINT 

264@ PRINT"YOU’VE HIRED & CREW OF ";CN;"." 
2645 GOSUB?2h6 :GOSUBS 2H 

2656 FORT=17T04 

2055 PRINT 

2666 PRINT"EACH CREW MEMBER WILL NEED " 
ebfO PRINT RI LEAST “:PNNC TOs" 8 lect; 
2675 IFPNCTI=1THENPRINT" “::GOTO2685 

2686 PRINT"S": 

2065 PRINT" OF ":Pec To 


e2eUSe PRINT AT ;PC Clos" GOLD PES PER ( - User Ts 

2676 PRINT"FOR EACH WEEK OF THE JOURNEY." 

2475 GOUSUBS246:PRINT:GOSUBS 244 

2106 PRINT HOW PANY “Uti lo: "S OF “sPecT > 

2114 S$="D0 YOU WANT TO BUY#" :GOSUB?1 64 

2120 PRINT 

2138 INPUTIS 

2146 PACTISVALC I$) :GOSUBS2H4 

2156 ITFPACT) 2° (CNSS*PNCT)9-1) THEN2268 

2166 IFRPACTI=@THENPRINT"IF YOU DON’T BUY ANY" :GO0TO 


2176 PRINT"IF YOU ONLY BUY "sPACT) sUS¢T): 
2175 IFPACTI=1THENPRINT" OF" :GO0TO21 S68 

21/76 PRINTS OF" 

2186 PRINTPS(T):;"," :GOSUBS206 

21748 PRINT"SOMEONE MIGHT GET ": 

22648 St="HUNGRY" 

2216 IFT=4THENS#="THIRSTY" 

2226 PRINTS®;"!":GOSUBP2ha 

2236 S¢= "DO YOU WANT TO TRY AGAIN" :GOSUBS14a6 
22496 INPUTPS:P#=LEFTS¢P#, 1) 

2242 [FPS<2"V"ANDPS<>"N" THEN2236 

22935 [FP#="N"THEN24466 

2250 PACTI=8:T=T-1:G0TO2416 

2266 TFPACT)*®PCCT? >MOTHEN22 76 

2269 GOTO2404 

22/76 Sé="VYOU DON’T HAVE ENQUGH MONEY FOR": GOSUBS1@ 4 
PRINTPACT 3 

PRINTUS¢7T):"S OF ";P#c1T> :GOSUBS 286 

S$="PLEASE TRY AGAIN®" :GOSUBS1H4:PACT)=8:T=T- 
s0TO249168 

MOSMO-¢ PACT) #POCCT 32 

PRINT :S#="PROVISIONS SO FAR: *" :GOSUB?1 a6 
BOSUBS 244 

FORTT=17T04 

FRINTPACTTs sUBCTT) s 

IFPACTT2=1THENPRINT" OF ":;:GOTO2446 

PRINTS OF |; 

FRINTPS<TT 2 

BOSUBS SHE 


mS 


fo ha fal 


Newer ee aos wo 
1 


Wm eS im oA RY 


Pah ha bo po ho Bo Ro Bo Po oh po 


BHEhHREBRLREE Es 


THE HOME COMPUTER ADVANCED COURSE 1315 














PROGRAMMING PROJECTS / SIMULATION GAME 


2466 NEXT 

2496 PRINT"MONEY LEFT = "iM0;" GOLD PIECES" 

2485 GOSUBS200:GOSUB? 208 

2490 MEXTT 

2500 GOSUIIBSZG1:PRINT:S#="END OF PROVISIONING#":G05 

UBS190:GOSUB92a6 

S510 PRINT: S$=K$:GOSUB?1GG:PRINT:  GOSUB?2a8 

2520 GETI1$:/= =." 'THENS5ea 

2999 RETURN 

3008 PRINTCHRS(147): REM STAGE 3 

3082 GOSUBS2a8 

2985 PRINT" STAGE 2 - OTHER GooDS" 

301@ PRINT" 9 ------- 0 we : 

3028 GOSUBS200 

3425 PRINT 

S030 S$=<"THERE ARE OTHER THINGS THAT Mays" :G05UBFiaa 
S¢="BE USEFUL ON THE VOYAGE, FOR #":G0SUB7188 
S$="EXAMPLE MEDICINE AND TRADING #";:GOSUBs1ia8 
GOSUB? 286 


Om cm tsa Uo be on 
ihe Sue on ee Amo om cnt 


arm Se She mS we ee ce 


MUN b bh ewww oo 


ds hg 


CA oS oe 


s) Of mr CO St LA Ge CA 


Jo 0) ta og CO oo 0 Oo Oo oo to od 0 to oo mo hdl go he oo 
ee ee el ee eC 





4008 
Agia 
 «4a28 
4025 
4634 
44035 
4a4a 
4045 
4455 
4068 


4204 
4205 
4206 
4z14 


& PRINT "MONEY 





St="THE 


St="OU May ALSO NEED WEAPONS. =":GOSUBSiaa 
GOSUB? 286 :GOSUB? 204 

FORT=1TO4 

PRINT 

PRINT" "s;O8¢T): 

S$=" COSTS*" :GOSUB?104 

PRINTOCST): 


PRINT" GOLD PIECE"; 
IFOC<T?=1THENPRINT" ":GOTO269 
PRINT"S" 

GOSUBSZ00 


S#t="WOULD YOU LIKE TO 
INPUTPS:PS=LEFTS¢P$,12 


BUY (Y OR Noe" :GOSUBT1E& 


TFPS<>"¥"ANDPS<>"N"THENS@ 75 
LFP$="N"THENS1 75 

GOSUBF2a0 

Sé="HOW MANY DO YOU WANT*" :GOSUBF1a8 
INPUTI# 


TTSVAL (183 
IFOC’T)*TT >MOTHENS1 58 
GOTOS1 40 


S$="YOU DON’T HAVE ENOUGH MONEY *" :GOSUB91 a6 
GOSUBS 286 

S$#="FLEASE ENTER AGAIN *" :GOSUB?1i 46 
GOSUBS 248 :G0TO31 38 

MO=MO-COCeC TTT? 

OACTISTT 

GOSUBF 204 

PRINT 


LEFT = ‘M0 
GOSUBS264:NExXT T 
GOSUBS264:PRINT :FRINT 

S$="END OF STAGE 3*" :GOSUB?1 66 


GOSUBS 266 :PRINT 
S#=kt : GOSUBF1 AG 
GETI¢:1TFIé=""THENS246 
RETURN 





REM CREL STATUS REPORT 
PRINTCHRE( 1442 

St$=—" CAPTAINS LOG*s" :GOSU 
Se" #" »G05 
GOSUBS 246 

PRINT"AT THE START OF WEEK" sWk 

STATE OF THE CRED I15:*" :GOSUBS1 44 
GOSUBS2ZHa:PRINT 
PRINT 

FORT=17TO14 
IFTStT.13=HTHENSI1& 
PRINTCS¢(TS¢T, 1333" 
LFTS¢T , 2)=-79?T HENS#=" DEAD 
IFTS(T, 23> 757THENS#="VERY HEALTHY?) #" :GOTO46?? 
IFTS¢t¢T , 2) +S58THENS#="HEALTHY)#" :GOTO4a 9? 
TFTS(T,2)>25THENS#="SICK ! jJ#" :G0TO48e? 
Sé$="WVERY SIEK ') ae” 

GOSUBSI A: GOSUBS Zhu 

NEXT 

GOSUBS Zhe: PRINT 

LJILJ=8 

FORT=17T0OS 

WhJslild+ § Ee To ele T a3 

NEXT 

St="WAGE BILL FOR THE WEEK#" :GOSUB?1 ab 
PRINTWL;"GOLD PIECES" 
GOSUBS Zu 

WTSWIT +liu 

St="TOTAL WAGES FOR VOYAGE 
PRINTHWT:"GOLG PIECES" 
GOSUB? 2H 4 
PRINT "MOWEY LEFT = "“sM0;"GOLD FIECES" 
PRINT :S¢=K$:G0SUBS164 
GETI#:IFIS=""THEN41 Fu 

RETURH 

REM FROVISIONS REFPURT 

PRIMTCHRE! 1473 ; 

FRINT"AT THE START OF WEEK" sk: GOSUBS 2h 
Sé="VOU HAWE THE FOLLOLIING*" :GOSUB?1 a6 


S50 FAR: 2#" :GOSUBS186 


1316 THE HOME COMPUTER ADVANCED COURSE 





Sé="PROVISIONS LEFT: *" :GOSUBS148 
PRINT : GOSUBY 264 

FORT=17T04 
TFPACTI=BORPACT 3=-?779T HENS 244 
PRINTPACT) :US¢TI3:"S OF "SPECT? 
X=PACTIA¢CCNEPNCT 2? 


PRINT" CENOLIGH FOR" ;INT¢xX);" WEEKS?" 
GOSUB? 268 

MET 

PRINT :St#=K% : GOSUBT1 46 
GETIS:1TFLé=""THENG295 

RETURM 


REM OTHER GOODS REPORT 
PRINTCHRé*147) 


H4 PRINT"AT THE START OF WEEK" ;WkK:GOSUB?2H8 


Age 
OSUB 
4394 


i hd i ho pa 
CA i om CA om 


238 
3246 
a are 
3278 





ig eo: 4 ut 


S$="YOU ALSO HAVE:#" :GOSUB?1 46 
PRINT : GOSUBS 2848 
IFOAC 1 3=8THEN4 332 


PRIMNTOAC13::S¢="BOTTLES OF MEDICINE®" :GOSUB?144 


GOSUBS 264 
TFOAt 2)=8THEN4342 
PRINTOA( 2)::5¢="GUNS#" :GOSUBF1 a8 


GOSUB?2HH 
[FORA S3=8THENS+ S52 
PRINTOAC3)::5¢="BAGS OF SALT#" :GOSUB?1 a4 


GOSUBS 248 

IFO0G* 49=6THEN434é2 
PRINTOAC 4d) ;:5¢="BALES 
GOSUBS2a4 

TFOAC S>=6THENSS72 
PRINTOA¢ 5) ::S¢="KNIVES#" :GOSUB?1 46 
GOSUBS ZH 

TFOAS 49=6THENS386 

PRINTOAC 6) ::S¢="JEWELS#" :GOSUB?146 
GOSUBS 264 :PRINT 

PRINT" YOU HAVE" sMO::Sé=" 
146 

BOSUBS ZB 

PRINT :S$=K% :GOSUB?I1 a 
GETI#:1FIS=""THEN4SSS 
RETURN 

REM CHECK WAGE BILL 

IFT SMOTHENS&@ 16 


OF CLOTH" : G0SUB? 106 


GOULD PIECES LEFI*® :G 


» GOTOSars 


PRINTCHRE(14 7) 

PRINT : PRINT s PRINT 

St="THE CRED! HAVE HEARD A RUMOUR®" :GOSUB?1 48 
St="THAT YOU DON’T HAVE ENOUGH®":GOSUBS16a © 
St="GOLD TO PAY THEM AT THE END#®" :GOSUB?1 48 
S$="CF THE VOYAGE.*" :GOSUB?1 646 

GOSUB?2H6 :PRINT 

St="THEY ARE GETTING ANGRY !!*" :GOSUBF1 an 
GOSUBS 208 :PRINT 

S$="LET’S HOPE YOU MANAGE TO MAKES" :GOSUB?1H4 
S$="4 TRADING PROFIT! #" :GUSUB?1 66 

GOSUBF 268 

PRINT: S#=K$:G0SUB? 108 

GETI#:1FIS=""THENSaSe 

RETURN 

REM ISSUE RATIONS 

PRINTCHRE<( 1472 

ISSUING RATIONS#" :GOSUB?1466 

Si ee ee ee ee *" :GOSUB?1&6 
GUSUBS2H4 :PRINT "VEER" (WK: PRINT 

H$= it pl by 

FORT=17T04 

HRT 3=1 

IFPACT?) #@THENS1 58 

PRINT"NO “:Pecio;" LEPI! |!" -GUSUBy eee 

S$="THE CRE) 1S GETTING WEAKER !!#" :GOSUBS166 
WF=16:GOSUB?7 3468 


* GOTOS2SH 


REC PN(T2#CNo #¢ JL-WkK+ 12 
IFRPACT? <ATHENS 268 
GOTOS276 
FRINT " RUNNING 
GOSUBR? 246 
St="00 YOU WANT TO PUT THE CREW ON®" :GOSLE?1é 
PRINT" HALF RATIOWMS OF "PST? 

INPUTIS: 1S=LEFTS¢(1%,1>? 

IFI $<" "AND E¢ 2 "MN" THENS226 

IFI¢="H" THENS276 
HROTI=.5:Ht="¥" 
WF=S:GOUSUB?3H8 
S#="THE CRE 15 
M=PHCT) #HRtT 2 #CN 
IFX?PACTOTHEMH=PAtT 9 

PACT I=PAtT )—x 
IFPACTI=8THENPALT I S-P FP 
PRINT RtUS¢13:'S OF  sPe los! 
PRINT :GOSUBS 208 :MEXT 

PRINT :S$=K : GO0SUB71 64 
GETI#:1Flé=""THEMS293 
RETURN 


SHORT OF “iPS 7D 


SETTING WEAKER! *" :GOSUB?1 a6 


ISSUED" 


oO 
ny 


ss 


<é 
Deer 


pacRy 


IAN McKINNELL 


CHANNELS 























OF THOUGHT 






sara 


We continue our series on the Spectrum’s 
operating system with a look at how the 
channels through which the micro sends 





2 data to the screen and ZX printer are 


4 handling different aspects of the displa 











selected and controlled. Our discussion 
takes in the use of system variables in 





i 





Bota 


On the Sinclair Spectrum the usual means of input 
is the keyboard and the usual outputs are either a 
television screen or a ZX printer. In the Spectrum 
system, each of these hardware items is called an 
input or output channel. The screen, for example, 
is referred to as an output channel. The actual data 
flowing to or from the computer, in the form of 
characters to the screen and information from the 
keyboard, is called a stream. A data stream is 
capable of being directed into different hardware 
channels, assuming that the channel hardware is 
capable of handling the stream in the correct 
fashion. 

We'll be taking a closer look at streams and 
channels in our next instalment. In the meantime, 
we'll begin our examination of the Spectrum I/O 
system with a look at the ‘output a character’ 
routine, which can be found at address &0010. ‘The 
character sent to this routine is forwarded to the 
screen or printer, depending upon which channel 
has been previously selected. Our diagram shows 




















CHANNEL K Spectrum 





the various channels on an unexpanded Spectrum 
and the stream numbers that are associated with 
them. Channels are named with a single letter, and 
streams are described by a number. In the 
unexpanded Spectrum only streams 0 to 3 are 
active. The Spectrum OS allocates streams to 
channels as shown in the table in the margin. 

Thus, when we want to output a character to a 
particular device we must first tell the Spectrum 
OS which stream we want it to be in. To write to the 
screen, we would select stream 2, as this is the one 
associated with channel S, and to do this we use a 
ROM routine at address &1601 to tell the OS which. 
stream we want to select. The stream number is 
placed in the A register, before calling the routine, 
which then opens up the hardware channel 
currently associated with that stream number. For 
example, to open channel S for output, we execute 
the following instructions: 


LD A,2 
CALL &1601 


Once a channel is open, sending a character to it is 
simply a matter of putting the character’s code into 
the A register and then executing an RST 
instruction to call the routine at address &0010. 
This is similar in some respects to the OSWRCH 

call on the BBC Micro, with the exception that we 
call an address in the ROM directly rather than via 
a vector. Channel S operates over the area of the 


Channel Crossings 


S — Upper part of display 


K — Used for output to lower 
part of display (used by 
BASIC for input and error 
messages) and input 
from keyboard 





P — Printer 


Using the Spectrum, data can be transferred to and from 
peripherals in ‘streams’ directed via (or ‘associated with’) 
different channels. On power-up, channels K, S and P are 
associated with streams (0 and 1), 2 and 3 respectively. Thus, 
PRINT #2 (i.e. to stream 2 — the screen) is the equivalent of the 
normal PRINT command. For example, PRINT #2; “This 
message will be printed on the screen” 


CHANNELP ZX Printer 





KEVIN JONES 


THE HOME COMPUTER ADVANCED COURSE 1317 








screen that is accessible via the normal Basic PRINT 
statements. However, it is also possible to access 
the lower two lines of the screen that are normally 
used by the BAsic interpreter for the output of error 
messages and prompts. As can be seen from the 
diagram, these lines form part of channel K. 

To send a character to these lines, we simply 
open channel K using: 


Ber wee 
CALL  &1601 


Similarly, the printer channel can be opened by 
loading the A register with 3. 

As well as standard characters, we can send 
control characters to any channel. Clearly, the 
effect that these control characters have will 
depend upon the channel in use, but it does mean 
that we can do the machine code equivalents of 
PRINT AT, PRINT INK, PRINT PAPER and so on. The 
following table shows some useful control codes 
and their functions when passed to channel S or K. 
Obviously, some will have no effect if sent to the 
ZX Printer (via channel P). 


The extra bytes requested by some control codes 
are the parameters that would normally follow 
them in a BASIC statement. For example, to execute 
_aPAPER 3 command, wed simply send the bytes 17 
and 3 to channel S. The following segment of a 
program shows the machine code equivalent of 
PRINT AT 10,10;“A”. 


SE62 18 ld a,2 
CDe@116 28 call #1661 
SE146 38 ld a,22 
D7 46 rst #18 
3E6A 36 ld a, 18 
D? 56 rst #16 
3E6A 78 ld a, 1@ 
D7 86 rst #18 
3E4 1 96 ld a,65 
D7 168 rst #16 
Cc? 118 ret 


Not too difficult, is it? One notable exception in 
the list of control codes is the absence of a code for 
CLS. To clear the screen, we must call another 
ROM routine at address &06DB. It is essential that 
channel S is open before we call it, and it’s also 
necessary to re-open channel S after we've used it 


1318 THE HOME COMPUTER ADVANCED COURSE 





SEB2 
CDe116 
CDDBG 4 
3E82 
CDO116 
C9 





;open channel S by 
;selecting stream 2 
stoken for AT 

soutput a char routine 
sy co-ordinate 


3x co-ordinate 


;ASCII] code for “A’ 


if we want to print anything else to the screen. ‘This 
routine will clear the screen: 


Id a,2 
call #1661 ;open channel § 
call #@édb ;clear the screen 
ld a,2 
call #1661 sre-open channel §S 
ret 

A useful attribute of the ‘output a character’ 


routine on a standard Spectrum is that numbers 
passed to it that represent Basic keywords are 
expanded by the routine and printed in full. Thus: 


LD A,249 
RST &10 


will — assuming channel S, P or K has been 
selected — print the keyword RANDOMISE to the 
screen. 

Graphic commands, such as PAPER, INK and 
BRIGHT, issued via the ‘output a character’ routine 
are operative only over that sequence of output 
characters — they are said to be temporary colour 
items. The PAPER n command, if issued outside of a 
PRINT statement, is a permanent command, and it 
remains operative until another PAPER command 
is issued. 





The two system variables of interest are called 
ATTR-P and MASK-P. The diagram above shows 
how these system variables control different 
aspects of the display. In ATTR-P, the three bits that 
control PAPER and INK colour on a permanent basis 
are given the values shown at the top of the next 
column. If the bit for FLASH or BRIGHT is set to one, 
then that feature is operational. ATTR-P is at 
address 23693. 

MASK-P is at address 23694 and any bit set to one 
in this byte will ensure that attributes on the screen 
at the relevant print position are not altered by the 
contents of ATTR-P. A further useful system 
variable is called PFLAG, and this is found at 
address 23697. This variable is also shown in the 

















diagram. I 
INK 9, INVERSE and OVER. 

There are two other system variables — ATTR-T 
and MASK-T — at addresses 23695 and 23696, 
respectively. These are arranged in a similar way to 
ATTR-P and MASK-P, but control the temporary 
colours (those in use in PRINT statements or those 
set up by sending control codes through the RTS 
&10 routine). 

Using ATTR-P and MASK-P to set up colours is 
quite easy; we simply manipulate the contents of 
the system variables, altering only those bits that 
we need to. This is easily done using the Z80’s AND 
and OR logical instructions. So, to execute a 
permanent PAPER 1:INK 3 command, we would set 
ATTR-P up to: | 





PAPER 1 INK 3 
using this piece of code: 
LD Aj 
LD (23693) ,A 
RET 


Of course, as with BAsIc permanent PAPER and INK 
commands, the new colours will not affect what’s 
been printed before and the screen will not go to 
the new PAPER colour until a CLS command, or its 
equivalent, has been executed. 

The graphics routines on the Spectrum are part 
of the BASIc interpreter program. We will now take 
a look at the PLOT and DRAW operations. When 
using these routines it is easy to bring about colour 
changes by altering the ATTR-P and MASK-P 
variables as we have already described here. 

The routines themselves are easy to use. The 
first of these, PLOT, is called at address &22E5. Its 
co-ordinates are passed to it in the BC register pair, 
(B holding the y co-ordinate and C the x co- 
ordinate). Thus, to execute the PLOT 100,100 
command from a machine code program wed 
simply execute these instructions: 


LD B00 —_;y co-ordinate 
LD C00 _;x co-ordinate 
CALL &22E5  ;doit 

RET 


Colour changes are easily performed; the 
following routine plots a red dot on the screen, and 
then restores ATTR-P to its previous state before 
returning to BASIC. 





3A845C 
FEFF 
28F9 
3AB85C 
ce 





Id a, (23693) 3get ATTR-P in A reg 

push af sand save on stack 

and 248 sclear low 3 bits to 8 

or 2 ;set bit 1 to give red ink 
id b, 166 sy co-ordinate 

Id c,166 3x co-ordinate 

call #22e5 3cal) PLOT 

pop af srestore original 

Id (23693) ,a sATTR-P contents 

ret 


1@ ; GET- 
28 Key: 
36 

46 

38 

68 


So far we’ve concentrated on channel S. What 
about channel K, which also has output facilities? 
We can write to the lower part of the screen if we 
want to, but what we put there will be overwritten 
when the operating system or interpreter 
generates a message. For input using this channel, 
we don’t even need to call a ROM routine! The 
keyboard is scanned once every 20 microseconds 
and some system variables are affected, 
depending on whether a key is being pressed or 
not. Two of particular use are LAST-K (at address 
23560), which holds the character code of the last 
key pressed, and a system variable at 23556, which 
holds the value 255 if a Key is notbeing pressed at 
that point in time. The routine here can thus be 
used to wait until a key is pressed and then return 
the character code in the A register. It simply 
checks the contents of address 23556 until it~ 
doesn’t equal 255. The value in LAST-K will then be 
that of the key being pressed. | 


CHAR routine 


ld a, (23556) ;check to see if 


cp 255 ;Key is being pressed | 
ir z,kKey sKeep checking 

Id a,2356@) sqet LAST-K in Aa 

ret 


Before leaving the keyboard, let’s look at a 
couple of system variables that can be useful. 





The other channel on an unexpanded Spectrum 
that is of use to us is channel P, which is used by the 
ZX Printer. This usually has stream 3 associated 
with it. Thus: 


LD A,3 
CALL = &1601 


will open channel P and subsequent characters will 
be printed on the ZX Printer if connected. It 
should be clear that BAsic makes wide use of the 
various channels: PRINT and LIST use channel S, 
LPRINT and LLIST use channel P and INPUT uses 
channel K. We can also add our own channels to 
the three we've discussed here, so that we can 
easily access additional devices such as 
Microdrives, different printers and other items of 
hardware. We'll look at this in more detail in the 
next instalment. 


THE HOME COMPUTER ADVANCED COURSE 1319 














Players In The Drama 

We show here three of the 
characters that the player 
controls in Shadowfire in 

different situations. On the left, 

Torik is in movement mode with 
the possible directions he can 





You have just 100 minutes to rescue an 
ambassador who, with vital plans, is being 
held captive aboard a starship. At your 
disposal is a team of six individuals with 
various skills... A familiar scenario, 
perhaps, but cursor control by means of icon 
selection adds an exciting new dimension to 
Beyond Software’s Shadowfire. 


GHANA 





Even the most casual observer will have noticed 
that computer games are becoming more 
sophisticated. Instead of slavishly reproducing 
arcade-style games or being content with text-only 


adventure games borrowed from the dungeons 


and dragons format, designers of home computer 
games are developing a style of their own. These 
games combine many of the features of the arcade 
and strategy formats to produce an entertainment 
which lasts considerably longer than the five 
minutes or so of the arcade action and is more 
demanding than even the brain-bending puzzles 
provided by the adventure. 

The scenario of Shadowfire is that the renegade 
General Zoff has captured Ambassador Kryxix, 
who has the plans for a new type of spaceship 
called Shadowfire. You, the player, are charged 
with rescuing the ambassador before he is forced 
into revealing the plans, and you have 100 minutes 
to accomplish your task. To assist you in the 
rescue, you have at your disposal six characters, 
each with different strengths and weaknesses. 

To get aboard Zoff’s spaceship, your team must 
be ‘teleported’ down. The only member who can 
organise this is the drone Manto, so he must be 
sent down first to lay the teleport beam for the 
others to follow. However, before you dispatch 
them, it is advisable to arm each of the characters 
according to their strengths and weaknesses from 
the weapons available. 

Shadowfire uses a unique system of moving 
characters, allowing them to pick up objects and to 
fight. Unlike other adventure-type programs that 
require the user to type in commands such as “Go 
North’ or ‘Pick up laser’, this game enables all 
functions to be performed by means of icons and a 
moving cursor — somewhat like the operating 
system used on the Apple Macintosh. To equip the 


1320 THE HOME COMPUTER ADVANCED COURSE 











team leader, Zark, with hand grenades, for 
example, you first select the Zark icon. Once this is 
chosen, the screen changes to a pictorial display of 
his strength, stamina and other attributes. On the 
right-hand side of the screen are three ‘monitor’ 
icons representing movement, battle mode and 
the objects screen. 

By selecting the objects screen with the cursor 
(which can be moved from the keyboard, joystick 
or light-pen), the screen changes again to display 
the objects that are in the same vicinity as the 
character as well as a number of ‘activity’ icons. By 
choosing the ‘pick up’ icon and then moving the 
cursor to the grenades icon, Zark will be equipped 
with grenades. 

Once armed and teleported down to the 
spaceship, the team can begin the search for 
General Zoff and Ambassador Kryxix. The 
spaceship consists of a number of rooms and 
corridors, some of which contain weapons or keys 
to enable you to open locked doors, while others 
conceal enemy guards who must be destroyed 
before you can proceed. If you lack the 
appropriate key you can call upon the services of 
Sevrina, who can pick locks. 

To make the best possible use of the 100 
minutes available you should develop a strategy. 
Some characters are better in some situations than 
others and so it is advisable to have the right 
person in the right place at the right time. 

What makes Shadowfire such an interesting 
game is the cursor control. The player is able to 
react to situations with the icon selection process 
much faster than he would if each command had 
to be typed in separately. Nevertheless, merely 
having fast reflexes will not allow you to complete 
the mission. Strategy and the ability to make quick 
decisions is also vital to a successful conclusion. 
































He 
Hey 


iy 


Be